Skip to content

hash's measured table: Emscripten linked at its optimization level, WASI without host-dependent debug information - #23

Merged
pinhopro merged 2 commits into
mainfrom
fix/hash-measure-order
Nov 16, 2026
Merged

pinhopro merged 2 commits into
mainfrom
fix/hash-measure-order

Conversation

@pinhopro

@pinhopro pinhopro commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Moves libs/hash to webcpporg/hash#2 (two commits) and changes tools/hash/measure.py and its test.

The measure lane failed on webcpp's main (run 43883027557, job "Own lane (hash, measure)"):

hkdf_extract over hmac_sha2_512 on emscripten: by size hash2, sodium, committed sodium, hash2

Root cause

  1. The failing row was a stale table, not the host. The committed table (2026-11-15) was measured before webcpp PR 18 ("link emscripten programs at their compile's level of optimization") reached the hash branch, so every Emscripten program had been linked at em++'s default -O0. Relinking today's hash2 object without -Os gives the committed 121,510 bytes exactly. Linked at -Os, as main does, hash2 is 21,083 bytes and libsodium 24,591, so hash2 is now the smaller one. The Mac reproduces CI's failure message exactly on main.
  2. A real host dependence, on WASI. WASI programs carried the DWARF of wasi-sdk's prebuilt libc++. That debug information names the paths of the machine that built the wasi-sdk release: /Users/runner/work/wasi-sdk/... in the macOS archive and /src/src/... in the Linux one. The result: 58 of the 146 WASI cells were 128 to 2,000 bytes larger on macOS than in a linux/amd64 container with the same wasi-sdk 34. For example, space-hkdf_extract_hash2_hmac_sha2_256 on wasip2 was 440,872 bytes on macOS and 439,848 on Linux. The debug sections were most of each program: that one is 59,161 bytes without them.

Fix

  • libs/hash test/measure/Jamfile links every WASI program with -Wl,--strip-debug. Emscripten's -Os link keeps no debug section already, and natively the size is the stripped executable.
  • tools/hash/measure.py (--check and --write) reads each WebAssembly program's custom sections, including every core module and component a wasip2 component nests. It fails, naming each program for size that has a .debug* section. The test came first: test_a_webassembly_program_with_debug_information_fails. RULES now says the .wasm carries no debug information.
  • The table was measured again on main with python3 tools/hash/measure.py --write on an idle machine (loaded: false), and the guide's generated tables were rewritten with doc_tables.py --write. Orders that change:
    • Emscripten: by size, hkdf_extract over hmac_sha2_512 is now hash2, sodium. By throughput, libsodium is now ahead of hash2 for hkdf_expand over hmac_sha2_256 and for hkdf over both hmacs; its median is 10.6 to 12.5 percent lower, past spec 4.2's 10 percent.
    • wasip2 and wasip3: by size, libsodium is now ahead of hash2 for hkdf_expand and hkdf, with BearSSL still first for hkdf.

Host independence

  • Emscripten: byte-identical on macOS arm64 and linux/amd64. hkdf_extract over hmac_sha2_512 is 21,083 bytes for hash2 and 24,591 for sodium on both hosts, with the same SHA-256.
  • WASI: sizes are now equal except a 64-byte residual (144 for OpenSSL) in 48 KDF programs. It comes from two __FILE__ strings of wasi-sdk's libc++abi (fallback_malloc.cpp, private_typeinfo.cpp) in the data section. These are real program bytes, so they cannot be stripped. No order can flip on them: the smallest gap between adjacent backends in any WebAssembly order is 1,212 bytes. Removing the residual would take one host-independent wasi-sysroot on every host, which is a toolchain decision outside this change.

Verification

  • Measure lane libs/hash/test/measure//measure, from scratch:
    • macOS: 284 cells agree.
    • linux/amd64 container (CI image, Ubuntu 24.04, Clang 18, the CI's emsdk and wasi-sdk): 284 cells agree; the native orders are skipped with the lane's one line.
    • Before the fix, both hosts failed with CI's message.
  • Tool tests: tools/test/hash_measure_test.py (16 cases) and hash_doc_tables_test.py ok; doc_tables.py --check ok; Pyright clean on both changed files.
  • hash lanes (-a, libs/hash/test and example): native 153 passed, wasip2 151, wasip3 151, Emscripten 118.

Remaining: wasi-sdk's libc++ debug information also inflates every webcpp WASI release program. Whether release links should strip it is a separate decision, not made here. bench/'s doc/measurements.throughput.json was measured before PR 18 as well and was not re-run.

🤖 Generated with Claude Code

R added 2 commits November 16, 2026 13:53
…ble is measured with Emscripten programs linked at their optimization level

main's measure lane failed: "hkdf_extract over hmac_sha2_512 on
emscripten: by size hash2, sodium, committed sodium, hash2". The
committed table was measured before PR 18 linked emscripten programs at
their compile's level of optimization, at em++'s -O0 (121,510 and
119,420 bytes); linked at -Os they are 21,083 and 24,591. The sizes do
not depend on the host: the two programs built on macOS arm64 and in a
linux/amd64 container with Emscripten 6.0.11 are byte-identical. The
table is measured again on main, which moves that order and three
Emscripten throughput orders.
…s debug information, and libs/hash links its WASI programs without it

wasi-sdk's prebuilt libc++ carries DWARF naming the include paths of the
machine that built the release, /Users/runner/work/wasi-sdk/... in the
macOS archive and /src/src/... in the Linux one, so a WASI program's
.wasm was 128 to 2,000 bytes larger on macOS than on Linux, and a
WebAssembly order, which the measure lane compares on every host, could
flip with the host. measure.py --check and --write now read each
WebAssembly program's custom sections, through every core module and
component a wasip2 component nests, and fail naming each program for
size that has a .debug section and test/measure/Jamfile, which links
WASI programs with --strip-debug at libs/hash's head
(hash_measure_test's test_a_webassembly_program_with_debug_information_fails).
RULES says the .wasm carries no debug information.

libs/hash moves to the head that links them so and measures the table
again: every wasip2 and wasip3 size changes, and libsodium becomes
smaller than hash2 for hkdf_expand and hkdf on WASI.
@pinhopro pinhopro changed the title libs/hash: the measured table measured with Emscripten programs linked at their optimization level hash's measured table: Emscripten linked at its optimization level, WASI without host-dependent debug information Nov 16, 2026
@pinhopro
pinhopro merged commit 96800a7 into main Nov 16, 2026
1 check passed
@pinhopro
pinhopro deleted the fix/hash-measure-order branch November 17, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant